import java.lang.reflect.InvocationTargetException;
import java.util.Base64;

public class HelloXClassLoader extends ClassLoader {
    public static void main(String[] args) {
        try {
            Class<?> hello = new HelloXClassLoader().findClass("Hello");
            hello.getDeclaredMethod("hello").invoke(hello.newInstance());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }

    /**
     * helloBase64通过在mac系统base64 xlass文件获取
     * @param name
     * @return
     * @throws ClassNotFoundException
     */
    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        String helloBase64 ="NQFFQf///8v/4/X/+f/x9v/w/+/3/+71/+3/7Pj/6/j/6v7/+cOWkZaLwf7//NfWqf7/+7yQm5r+//CzlpGasYqSnZqNq56dk5r+//qXmpOTkP7/9ayQio2cmrmWk5r+//W3mpOTkNGVnome8//4//f4/+nz/+j/5/7/7Leak5OQ09+ck56MjLOQnpuajd74/+bz/+X/5P7/+reak5OQ/v/vlZ6JntCTnpGY0LCdlZqci/7/75WeiZ7Qk56RmNCshoyLmpL+//yQiov+/+qzlZ6JntCWkNCvjZaRi6yLjZqeksT+/+yVnome0JaQ0K+NlpGLrIuNmp6S/v/4j42WkYuTkf7/6tezlZ6JntCTnpGY0KyLjZaRmMTWqf/e//r/+f///////f/+//j/9//+//b////i//7//v////rVSP/+Tv////7/9f////n//v////7//v/0//f//v/2////2v/9//7////2Tf/97fxJ//tO/////v/1////9f/9////+//3//r//v/z/////f/y";
        byte[] bytes = complementer(helloBase64);
        return defineClass(name, bytes, 0, bytes.length);
    }

    /**
     * 作业提示
     * @param base64Str
     * @return
     */
    private  byte[] decrypt(String base64Str) {
        byte[] bytes = Base64.getDecoder().decode(base64Str);
        for(int i=0;i<bytes.length;i++)
            bytes[i]=(byte)(255-bytes[i]);
        return bytes;
    }



    /**
     * -54,-2,-70,-66,0,0,0,52,0,28,10 class byte[]
     * 53 , 1,69  ,65,-1,-1,-1,-53,-1,-29,-11,-1 xlass byte[]
     * 通过对比class和xlass的byte[] 发现xlass求反后结果为需要结果
     * @param base64Str
     * @return
     */
    private  byte[] complementer(String base64Str) {
        byte[] decryptdecode = Base64.getDecoder().decode(base64Str);
        for(int i=0;i<decryptdecode.length;i++)
            decryptdecode[i]= (byte) ~decryptdecode[i];
        return decryptdecode;
    }
}